"""utils module"""

import numpy as np

from mindspore.ops import operations as P
import mindspore.numpy as mnp
import mindspore.nn as nn
from mindspore.common.tensor import Tensor
from mindspore.common.initializer import TruncatedNormal
import mindspore.common.dtype as mstype
from scipy.special import softmax

TRUNCATED_NORMAL_STDDEV_FACTOR = np.asarray(.87962566103423978, dtype=np.float32)

def lecun_init(fan_in, initializer_name='linear'):
    scale = 1.0
    if initializer_name == 'relu':
        scale *= 2
    weight_init = TruncatedNormal(sigma=np.sqrt(scale/fan_in)/TRUNCATED_NORMAL_STDDEV_FACTOR)
    return weight_init

def glorot_uniform(fan_in, fan_out, weight_shape):
    limit = np.sqrt(6/(fan_in + fan_out))
    return np.random.uniform(-limit, limit, size=weight_shape)
